/*
 * FileProcess.cpp
 *
 *  Created on: Mar 13, 2014
 *      Author: igor
 */

#include "FileProcess.h"
#include "Student.h"
#include "stdio.h"
#include <string>

#define SIZE 19;

FileProcess::FileProcess() {
	numLines=0;
	id[19].Info[40] = '\0';
}

FileProcess::~FileProcess() {
}

void FileProcess::OpenFile() {

//	printf("FileProcess::OpenFile()\n");

	int j=0;
	int i=0;
	int count=0;

	FILE *arquivo = fopen("./src/Input_new.txt", "r");

	if(arquivo == NULL) {
		printf( "Erro na abertura do arquivo\n");
		return;
	}

	while((c = getc(arquivo)) != EOF) {

		if((i>0)&&(c==' ')) {
			count ++;
			if(count == 1)
				id[i].namePosition = j+1;
			if(count == 2)
				id[i].respPosition = j+1;
		}
		id[i].Info[j]=c;
//		printf("[%d][%d]:%c ", i, j, id[i].Info[j]);
//		printf("[%d]%c ", j, id[i].Info[j]);
		j++;
		if(c=='\n') {
			id[i].numLines = i;
			id[i].length = j;
			id[i].Info[j]='\0';
//			printf("\n[%d][%d]: %d %d", i, j, namePosition, respPosition);
//			printf("\n[%d][%d]", i, j);
//			printf("\n[%d][%d]", id[i].numLines, id[i].length);
			i++;
			count = 0;
			j=0;
		}
	}
//	printf("\n\n%s \n\n", id[0].Info);
//	fflush(stdin);
}

void FileProcess::ProcessingFile() {

//	printf("\n\nFileProcess::ProcessingFile\n");
	for(int i=0; i<19; i++) {
//		printf("\n\n[%d][%d]", id[i].numLines, id[i].length);
//		printf("\n%s", id[i].Info);
//		printf("\n[%d]: %d %d", i, id[i].namePosition, id[i].respPosition);
		Student *m_Student = new Student(id[i]);
		printf("\n[%d]: ",i);
		if(i==0) {
			m_Student->getResp(id[i]);
		}
		if(i>0) {
			m_Student->getRegister(id[i]);
			m_Student->getName(id[i]);
			m_Student->getValues(id[i]);
		}
//		m_Student->getRegister();
	}
//	Student *m_Student = new Student(numLines);

}









